# Definition for singly-linked list.
class ListNode(object):
    def __init__(self, x):
        self.val = x
        self.next = None

class Solution(object):
    def removeElements(self, head, val):
        """
        :type head: ListNode
        :type val: int
        :rtype: ListNode
        """
        if not head :
            return None
        phead = ListNode(None)
        phead.next = head
        curl = phead
        cur = head
        while cur!= None:
            if cur.val == val:
                curl.next = cur.next
                cur = cur.next
            else:
                curl = curl.next
                cur = cur.next
        return phead.next





l1 = ListNode(1)
l1.next = ListNode(2)
l1.next.next = ListNode(4)
l1.next.next.next = ListNode(2)

m = Solution()
s = m.removeElements(l1,2)

while s!= None:
    print(s.val)
    s = s.next